//
//  UIBarButton+exsion.swift
//  WeiBo
//
//  Created by 李立达 on 15/12/5.
//  Copyright © 2015年 heima11. All rights reserved.
//

import UIKit


let itemTitleFontsize : CGFloat = 14

let itemTitleColor : UIColor = UIColor(white: 80 / 255, alpha: 1.0)
extension UIBarButtonItem {



    convenience init(imgName : String? = nil ,title : String? = nil ,target:AnyObject?, anction : Selector)
    {
        self.init()
        
        let Button = UIButton()
        
        Button.addTarget(target, action: anction, forControlEvents: UIControlEvents.TouchUpInside)
    
        
        if  let img = imgName {
        
            Button.setImage(UIImage(named: img), forState: UIControlState.Normal)
            
            Button.setImage(UIImage(named: "\(img)_highlighted"), forState: UIControlState.Highlighted)
        }
        
        if let ti = title {
        
            Button.setTitle(ti, forState: UIControlState.Normal)
            
            Button.setTitleColor(itemTitleColor, forState: .Normal)
        
            Button.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
            
            Button.titleLabel?.font = UIFont.systemFontOfSize(itemTitleFontsize)
        }
        
        Button.sizeToFit()
        
        customView = Button
    }

}
